<?php

use App\Util\Helper;
use Plugins\AdminBasic\Http\Admin\Controller\OperationLogsController;
use Sc\Util\HtmlStructure\Form\FormItem;
use Sc\Util\HtmlStructure\Html\Html;
use Sc\Util\HtmlStructure\Html\Js\JsService;
use Sc\Util\HtmlStructure\Table;

Html::create('操作日志列表');

$table = Table::create(Helper::route()->to([OperationLogsController::class, 'listsData'])->url(), 'operation_logs');

$table->addColumns(
    Table\Column::selection(),
    Table\Column::normal('请求模块', 'module')->addSearch()->setAttr('width', 100),
    Table\Column::normal('请求ID', 'request_id')->addSearch()->setAttr('width', 130),
    Table\Column::normal('请求方式', 'method')->addSearch()->setAttr('width', 100),
    Table\Column::normal('请求地址', 'url')->align('left')->addSearch('like_right'),
    Table\Column::normal('描述', 'des')->align('left')->addSearch('like'),
    Table\Column::normal('时间', 'create_time')->setAttr('width', 180)->addSearch('between'),
    Table\Column::event('操作')->setAttr('width', 180)
);

$table->addSearch(FormItem::text('data')->placeholder('请求参数:ket=value'));
$table->addSearch(FormItem::text('user_info')->placeholder('用户信息:ket=value||user_id'));
$table->setHeaderEvent("@primary.Refresh.刷新数据", "this.operation_logsGetData()");

// ===========================================
// 新页面: 注释代码为Vue组件模式， 默认为iframe模式
// ===========================================

//$component = Temporary::create('create')->setContent(include __DIR__ . '/form.sc.php');

//$table->setHeaderEvent('@primary.Plus.新增',
//    Table\EventHandler::window('新增')->setConfig(['width' => '1000px'])->setComponent($component)
//);

//$table->setRowEvent('@primary.Edit.编辑',
//    Table\EventHandler::window('编辑')->setConfig(['width' => '1000px'])->setComponent($component)
//);

$table->setHeaderEvent('@primary.更新请求描述', function (){
    return Table\EventHandler::get(Helper::route()->to([OperationLogsController::class, 'cacheRouteDesMap']), [])
        ->confirmMessage("确认更新吗？")
        ->success(JsService::message("成功"));
});


$table->setRowEvent("@primary.明细数据", function () {
    return Table\EventHandler::window('明细数据')->setUrl(
        Helper::route()->to([OperationLogsController::class, 'detail']), ['id' => '@id']
    );
});

$table->setMaxHeight();


return $table->render();
